/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdvogadoGUI.java
 *
 * Created on 16/07/2009, 21:57:48
 */

package gui;

import facade.AdvogadoFacade;
import java.awt.Component;

/**
 *
 * @author andrehadm
 */
public class AdvogadoGUI extends javax.swing.JFrame {

    /**Atributos*/
    private AdvogadoFacade advogadoFacade;

    /** Creates new form AdvogadoGUI */
    public AdvogadoGUI() {
        advogadoFacade = new AdvogadoFacade();
        initComponents();        
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jFrame1 = new javax.swing.JFrame();
        jPopupMenu1 = new javax.swing.JPopupMenu();
        barraDeFerramentas = new javax.swing.JToolBar();
        jButtonClienteNovo = new javax.swing.JButton();
        jButtonClientePesquisa = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        jButtonProcessoNovo = new javax.swing.JButton();
        jButtonProcessosPesquisa = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        jButton_Audiencia = new javax.swing.JButton();
        jButton_Financeiro = new javax.swing.JButton();
        jButton_Relatorios = new javax.swing.JButton();
        jButtonTeste = new javax.swing.JButton();
        jPanelAreaDeTrabalho = new javax.swing.JPanel();
        barraDeMenu = new javax.swing.JMenuBar();
        jMenu_Arquivo = new javax.swing.JMenu();
        jMenuItem_Sair = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Advogado");
        setName("janelaPrincipal"); // NOI18N

        barraDeFerramentas.setFloatable(false);
        barraDeFerramentas.setRollover(true);

        jButtonClienteNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/clienteNovo.png"))); // NOI18N
        jButtonClienteNovo.setToolTipText("Criar novo cliente");
        jButtonClienteNovo.setFocusable(false);
        jButtonClienteNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonClienteNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonClienteNovo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonClienteNovoMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButtonClienteNovo);

        jButtonClientePesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/clientePesquisa.png"))); // NOI18N
        jButtonClientePesquisa.setToolTipText("Pesquisar por cliente");
        jButtonClientePesquisa.setFocusable(false);
        jButtonClientePesquisa.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonClientePesquisa.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonClientePesquisa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonClientePesquisaMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButtonClientePesquisa);
        barraDeFerramentas.add(jSeparator1);

        jButtonProcessoNovo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/processoNovo.png"))); // NOI18N
        jButtonProcessoNovo.setFocusable(false);
        jButtonProcessoNovo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonProcessoNovo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonProcessoNovo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonProcessoNovoMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButtonProcessoNovo);

        jButtonProcessosPesquisa.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/processos.png"))); // NOI18N
        jButtonProcessosPesquisa.setFocusable(false);
        jButtonProcessosPesquisa.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonProcessosPesquisa.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonProcessosPesquisa.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonProcessosPesquisaMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButtonProcessosPesquisa);
        barraDeFerramentas.add(jSeparator2);

        jButton_Audiencia.setText("Audiências");
        jButton_Audiencia.setFocusable(false);
        jButton_Audiencia.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Audiencia.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        barraDeFerramentas.add(jButton_Audiencia);

        jButton_Financeiro.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagens/financas.png"))); // NOI18N
        jButton_Financeiro.setFocusable(false);
        jButton_Financeiro.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Financeiro.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        barraDeFerramentas.add(jButton_Financeiro);

        jButton_Relatorios.setText("Relatorios");
        jButton_Relatorios.setFocusable(false);
        jButton_Relatorios.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton_Relatorios.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton_Relatorios.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButton_RelatoriosMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButton_Relatorios);

        jButtonTeste.setText("Teste");
        jButtonTeste.setFocusable(false);
        jButtonTeste.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButtonTeste.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButtonTeste.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jButtonTesteMouseClicked(evt);
            }
        });
        barraDeFerramentas.add(jButtonTeste);

        javax.swing.GroupLayout jPanelAreaDeTrabalhoLayout = new javax.swing.GroupLayout(jPanelAreaDeTrabalho);
        jPanelAreaDeTrabalho.setLayout(jPanelAreaDeTrabalhoLayout);
        jPanelAreaDeTrabalhoLayout.setHorizontalGroup(
            jPanelAreaDeTrabalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        jPanelAreaDeTrabalhoLayout.setVerticalGroup(
            jPanelAreaDeTrabalhoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 537, Short.MAX_VALUE)
        );

        jMenu_Arquivo.setLabel("Arquivo");

        jMenuItem_Sair.setLabel("Sair");
        jMenuItem_Sair.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jMenuItem_SairMouseClicked(evt);
            }
        });
        jMenu_Arquivo.add(jMenuItem_Sair);

        barraDeMenu.add(jMenu_Arquivo);

        jMenu2.setText("Edit");
        barraDeMenu.add(jMenu2);

        setJMenuBar(barraDeMenu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(barraDeFerramentas, javax.swing.GroupLayout.DEFAULT_SIZE, 812, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jPanelAreaDeTrabalho, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(barraDeFerramentas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanelAreaDeTrabalho, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuItem_SairMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jMenuItem_SairMouseClicked
        System.exit(0);
    }//GEN-LAST:event_jMenuItem_SairMouseClicked

    private void jButtonClienteNovoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonClienteNovoMouseClicked

        if (jButtonClienteNovo.isEnabled()) {
            ClienteGUI clienteGUI = new ClienteGUI(jPanelAreaDeTrabalho, barraDeFerramentas, advogadoFacade);
            clienteGUI.setSize(jPanelAreaDeTrabalho.getWidth() - 15, jPanelAreaDeTrabalho.getHeight() - 15 );
            jPanelAreaDeTrabalho.removeAll();
            jPanelAreaDeTrabalho.add(clienteGUI);
            jPanelAreaDeTrabalho.revalidate();
            System.out.println(barraDeFerramentas.getComponentCount());
            desabilitaBotoesBarraDeFerramentas();
            System.out.println("Novo Cliente.");
        }
}//GEN-LAST:event_jButtonClienteNovoMouseClicked

    private void jButtonProcessoNovoMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonProcessoNovoMouseClicked
            
        if (jButtonProcessoNovo.isEnabled()) {
            ProcessoGUI processoGUI = new ProcessoGUI(jPanelAreaDeTrabalho, barraDeFerramentas, advogadoFacade);
            processoGUI.setSize(jPanelAreaDeTrabalho.getWidth() - 15, jPanelAreaDeTrabalho.getHeight() - 15 );
            jPanelAreaDeTrabalho.removeAll();
            jPanelAreaDeTrabalho.add(processoGUI);
            jPanelAreaDeTrabalho.revalidate();
            System.out.println(barraDeFerramentas.getComponentCount());
            desabilitaBotoesBarraDeFerramentas();
            System.out.println("Novo Processo.");
        }
        //TesteLimpar tl =  new TesteLimpar(this, rootPaneCheckingEnabled);
        //tl.setEnabled(true);
        //tl.setVisible(true);
    }//GEN-LAST:event_jButtonProcessoNovoMouseClicked

    private void jButtonTesteMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonTesteMouseClicked
        TesteLimpar tl = new TesteLimpar(this, rootPaneCheckingEnabled);
        tl.setVisible(true);
    }//GEN-LAST:event_jButtonTesteMouseClicked

    private void jButtonClientePesquisaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonClientePesquisaMouseClicked
        if (jButtonClientePesquisa.isEnabled()) {
            ClientePesquisaGUI clientePesquisaGUI = new ClientePesquisaGUI(jPanelAreaDeTrabalho, barraDeFerramentas, advogadoFacade);
            clientePesquisaGUI.setSize(jPanelAreaDeTrabalho.getWidth() - 15, jPanelAreaDeTrabalho.getHeight() - 15 );
            jPanelAreaDeTrabalho.removeAll();
            jPanelAreaDeTrabalho.add(clientePesquisaGUI);
            jPanelAreaDeTrabalho.revalidate();
            System.out.println(barraDeFerramentas.getComponentCount());
            desabilitaBotoesBarraDeFerramentas();
            System.out.println("Cliente Pesquisa.");
        }
    }//GEN-LAST:event_jButtonClientePesquisaMouseClicked

    private void jButtonProcessosPesquisaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButtonProcessosPesquisaMouseClicked
        if (jButtonProcessosPesquisa.isEnabled()) {
            ProcessoPesquisaGUI processoPesquisaGUI = new ProcessoPesquisaGUI(jPanelAreaDeTrabalho, barraDeFerramentas, advogadoFacade);
            processoPesquisaGUI.setSize(jPanelAreaDeTrabalho.getWidth() - 15, jPanelAreaDeTrabalho.getHeight() - 15 );
            jPanelAreaDeTrabalho.removeAll();
            jPanelAreaDeTrabalho.add(processoPesquisaGUI);
            jPanelAreaDeTrabalho.revalidate();
            System.out.println(barraDeFerramentas.getComponentCount());
            desabilitaBotoesBarraDeFerramentas();
            System.out.println("Processo Pesquisa.");
        }
    }//GEN-LAST:event_jButtonProcessosPesquisaMouseClicked

    private void jButton_RelatoriosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton_RelatoriosMouseClicked
        if (jButton_Relatorios.isEnabled()) {
            RelatoriosGUI relatoriosGUI = new RelatoriosGUI(jPanelAreaDeTrabalho, barraDeFerramentas, advogadoFacade);
            relatoriosGUI.setSize(jPanelAreaDeTrabalho.getWidth() - 15, jPanelAreaDeTrabalho.getHeight() - 15 );
            jPanelAreaDeTrabalho.removeAll();
            jPanelAreaDeTrabalho.add(relatoriosGUI);
            jPanelAreaDeTrabalho.revalidate();
            System.out.println(barraDeFerramentas.getComponentCount());
            desabilitaBotoesBarraDeFerramentas();
            System.out.println("Relatorios.");
        }
    }//GEN-LAST:event_jButton_RelatoriosMouseClicked

    //Ainda não está sendo usado
    public void atualizarAreaDeTrabalho() {
        jPanelAreaDeTrabalho.removeAll();
        System.out.println("Removi tudo.");
        jPanelAreaDeTrabalho.revalidate();
        System.out.println("Revalidei.");
        //jPanel_AreaDeTrabalho.repaint();
    }

    private void desabilitaBotoesBarraDeFerramentas(){
        for (Component botoes: barraDeFerramentas.getComponents()  ) {
            botoes.setEnabled(false);
        }
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {

//ToDo  Ativar quando o programa tiver pronto!!!

//                try {
//                    UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//                } catch (ClassNotFoundException ex) {
//                    Logger.getLogger(AdvogadoGUI.class.getName()).log(Level.SEVERE, null, ex);
//                } catch (InstantiationException ex) {
//                    Logger.getLogger(AdvogadoGUI.class.getName()).log(Level.SEVERE, null, ex);
//                } catch (IllegalAccessException ex) {
//                    Logger.getLogger(AdvogadoGUI.class.getName()).log(Level.SEVERE, null, ex);
//                } catch (UnsupportedLookAndFeelException ex) {
//                    Logger.getLogger(AdvogadoGUI.class.getName()).log(Level.SEVERE, null, ex);
//                }
                new AdvogadoGUI().setVisible(true);
            }
        });
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToolBar barraDeFerramentas;
    private javax.swing.JMenuBar barraDeMenu;
    private javax.swing.JButton jButtonClienteNovo;
    private javax.swing.JButton jButtonClientePesquisa;
    private javax.swing.JButton jButtonProcessoNovo;
    private javax.swing.JButton jButtonProcessosPesquisa;
    private javax.swing.JButton jButtonTeste;
    private javax.swing.JButton jButton_Audiencia;
    private javax.swing.JButton jButton_Financeiro;
    private javax.swing.JButton jButton_Relatorios;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuItem_Sair;
    private javax.swing.JMenu jMenu_Arquivo;
    private javax.swing.JPanel jPanelAreaDeTrabalho;
    private javax.swing.JPopupMenu jPopupMenu1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    // End of variables declaration//GEN-END:variables

}
